import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class MemberSignService extends BaseService<any> {
  private readonly logger = new Logger(MemberSignService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getPage
   * 对应 PHP: MemberSignService_admin::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(where: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: $member_where = [];         if (isset($where[ 'keywords' ]) && $where[ 'keywords' ] != '') {             $member_where = [ [ 'member.member_no|member....
const member_where = [];
        if (typeof where[ 'keywords' )) && where[ 'keywords' ] != '') {
            const member_where = [ [ 'member.member_no|member.nickname|member.mobile', 'like', '%' . this.model.handelSpecialCharacter(where[ 'keywords' ))  + '%' ] ];
  }

  /**
   * makeUp
   * 对应 PHP: MemberSignService_admin::makeUp()
   * 逻辑类型: undefined - undefined
   */
  async makeUp(data: any) {
    // 基于PHP真实逻辑: makeUp
    // PHP原文: //日签奖励         if (!empty($data[ 'day_award' ])) {             $data[ 'day_award' ] = ( new CoreMemberService() )->getGiftContent($this->site_id, $dat...
//日签奖励
        if (!!data[ 'day_award' ))) {
            data[ 'day_award' ] = ( this.coreMemberService ).getGiftContent(this.site_id, data[ 'day_award' )];
  }

  /**
   * getInfo
   * 对应 PHP: MemberSignService_admin::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(sign_id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $field = 'sign_id, site_id, member_id, days, day_award, continue_award, continue_tag, create_time, is_sign';         return $this->model->where([ [ 's...
const field = 'sign_id, site_id, member_id, days, day_award, continue_award, continue_tag, create_time, is_sign';
        return this.model.where([ [ 'sign_id', '=', sign_id ], [ 'site_id', '=', this.site_id ) )).field(field).append([ 'is_sign_name' )).findOrEmpty().toArray(];
    }

    /**
     * 设置签到设置
     * @param value
     * @return bool
     */
    async setSign(value)
    {
//        if (!value[ 'sign_period' ))) throw new AdminBusinessException('SIGN_PERIOD_CANNOT_EMPTY'];
//        if (value[ 'sign_period' ) < 2 || value[ 'sign_period' ) > 365) throw new AdminBusinessException('SIGN_PERIOD_BETWEEN_2_365_DAYS');
//        if (!!value[ 'continue_award' ))) {
//            foreach (value[ 'continue_award' ) as v) {
//                if (v[ 'continue_sign' ) < 2 || v[ 'continue_sign' ) > 365) throw new AdminBusinessException('CONTINUE_SIGN_BETWEEN_2_365_DAYS'];
//                if (v[ 'continue_sign' ) > value[ 'sign_period' )) throw new AdminBusinessException('CONTINUE_SIGN_CANNOT_GREATER_THAN_SIGN_PERIOD');
//            }
//
  }

  /**
   * getSign
   * 对应 PHP: MemberSignService_admin::getSign()
   * 逻辑类型: undefined - undefined
   */
  async getSign() {
    // 基于PHP真实逻辑: getSign
    // PHP原文: $info = ( new CoreConfigService() )->getConfig($this->site_id, 'SIGN_CONFIG');         if (empty($info)) {             $info = [];             $info[ ...
const info = ( this.coreConfigService ).getConfig(this.site_id, 'SIGN_CONFIG');
        if (!info)) {
            const info = [];
            info[ 'value' ] = [
                is_use: 0,
                sign_period: '',
                day_award: '',
                continue_award: [],
                rule_explain: ''
            ];
  }
}
